package lar.system.engine;

import android.util.Log;
import android.view.KeyEvent;
import lar.system.opengl.GLKeyHandler;

public class Keyboard 
{
	
	public static void keyEvent(GLKeyHandler listener, float x, float y)
	{
		//Log.d("R", "x: " + x + " y: " + y);
		if(y > 0.75f) //number
		{
			int n = ((int)(x * 10) + 1)%10;
			listener.onKeyDown(2, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0+n));
		}
		else if(y > 0.5f)
		{
			final int arr[] = { KeyEvent.KEYCODE_Q,
								KeyEvent.KEYCODE_W,
								KeyEvent.KEYCODE_E, 
								KeyEvent.KEYCODE_R, 
								KeyEvent.KEYCODE_T, 
								KeyEvent.KEYCODE_Y, 
								KeyEvent.KEYCODE_U, 
								KeyEvent.KEYCODE_I, 
								KeyEvent.KEYCODE_O, 
								KeyEvent.KEYCODE_P
								};
			listener.onKeyDown(2, new KeyEvent(KeyEvent.ACTION_DOWN, arr[(int)(x*10)]));
		}
		else if(y > 0.25f)
		{
			final int arr[] = { KeyEvent.KEYCODE_A,
								KeyEvent.KEYCODE_S,
								KeyEvent.KEYCODE_D, 
								KeyEvent.KEYCODE_F, 
								KeyEvent.KEYCODE_G, 
								KeyEvent.KEYCODE_H, 
								KeyEvent.KEYCODE_J, 
								KeyEvent.KEYCODE_K, 
								KeyEvent.KEYCODE_L, 
								KeyEvent.KEYCODE_DEL
								};
			listener.onKeyDown(2, new KeyEvent(KeyEvent.ACTION_DOWN, arr[(int)(x*10)]));
		}
		else
		{
			final int arr[] = { KeyEvent.KEYCODE_Z,
								KeyEvent.KEYCODE_X,
								KeyEvent.KEYCODE_C, 
								KeyEvent.KEYCODE_V, 
								KeyEvent.KEYCODE_B, 
								KeyEvent.KEYCODE_N, 
								KeyEvent.KEYCODE_M, 
								};
			if(x < 0.7f) listener.onKeyDown(2, new KeyEvent(KeyEvent.ACTION_DOWN, arr[(int)(x*10)]));
			else
			{
				if(x < 0.85f) listener.onKeyDown(2, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SPACE));
				else listener.onKeyDown(2, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
			}
		}
		
		
	}

}
